﻿using System;

namespace Com.OpenCode.Framework.Core
{
    class ConditionDoozer : IDoozer
    {
        public string Name
        {
            get { return "Condition"; }
        }

        public object BuildItem(BuildItemEventArgs args)
        {
            object obj = null;
            if (Name == args.Plugin.Name)
            {
                string className = args.Plugin.Properties.GetString("Type");
                obj = args.Plugin.Addin.Runtime.CreateObject(className);
            }
            else
            {
                throw new Exception(string.Format("{0}解析器无法解析插件节点{1}，请使用正确的解析器。", Name, args.Plugin.Name));
            }
            return obj;
        }


        public static ICondition BulidItem(Addin addin, string Id)
        {
            Plugin plugin = addin.Plugin.Search("Condition", "Id", Id);
            if (plugin != null)
            {
                return plugin.Addin.Bulid(plugin) as ICondition;
            }
            return null;
        }

    }
}
